import axios from "axios"
import router from "@/routes"
const request = axios.create({
  baseURL: "http://127.0.0.1:8080/api/",
})
export const URL = "127.0.0.1:8080/api/"
request.defaults.withCredentials = true //设置为true
request.interceptors.request.use(
  function (config) {
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)

request.interceptors.response.use(   
  function (response) {
    // 未登录则跳转登录页
    if (response?.data?.code === 40100) {
      //@ts-ignore
      showFailToast("请先登录！");
      router.push('/user/login')
    }
    return response.data
  },
  function (error) {
    return Promise.reject(error)
  }
)

export default request
   